<template>
  <div class="rose-echarts">
    <base-echarts :options="options" :canvas-height="height" />
  </div>
</template>

<script setup lang="ts">
import type { EChartsOption } from 'echarts';
import { computed } from 'vue';
import type { IPieDataItem } from '@/components/page-echarts/types/myecharts';

interface IProps {
  height?: string;
  data?: IPieDataItem[];
}

const props = withDefaults(defineProps<IProps>(), {
  height: '300px'
});

const options = computed<EChartsOption>(() => {
  return {
    toolbox: {
      show: true,
      feature: {
        mark: { show: true },
        dataView: { show: true, readOnly: false },
        restore: { show: true },
        saveAsImage: { show: true }
      }
    },
    tooltip: {
      trigger: 'item'
    },
    series: [
      {
        name: '访问来源',
        type: 'pie',
        // 内半径/外半径的大小
        radius: [10, 160],
        // 设置区域的位置
        center: ['50%', '65%'],
        roseType: 'area', // 圆心角一样, 通过半径的不同表示大小
        itemStyle: {
          borderRadius: 8
        },
        data: props.data,
        label: {
          show: false
        }
      }
    ]
  };
});
</script>

<style scoped lang="scss">
.rose-echarts {
}
</style>
